package com.itrus.auth.demo.person.face;

import com.itrus.auth.demo.core.BaseAuth;
import com.itrus.auth.demo.core.Config;
import com.itrus.auth.demo.person.basic.PersonBasicAuth;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : peigen
 * @since: 2023/8/2 18:08
 */
public class H5BlinkAuth extends BaseAuth {

    protected String REQUEST_PATH = "/h5/blink";
    protected String SERVICE_CODE = "idc2003";


    public H5BlinkAuth(Config config) {
        super.config = config;
    }

    /**
     * 获取h5眨眼连接地址
     *
     * @param name
     * @param idCard
     * @param fromType
     * @param blinkCallbackUrl
     * @param successLocation
     * @param failLocation
     */
    public void auth(String name, String idCard, String fromType,
                     String blinkCallbackUrl, String successLocation, String failLocation) {
        Map<String, String> requestMap = new HashMap<>(8);
        requestMap.put("appId", config.getAppId());
        requestMap.put("serviceCode", SERVICE_CODE);
        requestMap.put("name", name);
        requestMap.put("idnumber", idCard);
        try {
            requestMap.put("blinkUrl", URLEncoder.encode(blinkCallbackUrl, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // ignore
        }
        // browser：表示在浏览器启动刷脸
        // App：表示在 App 里启动刷脸
        requestMap.put("fromType", fromType);
        requestMap.put("successLocation", successLocation);
        requestMap.put("failLocation", failLocation);


        doRequest(REQUEST_PATH, requestMap);
    }

    @Override
    public String getServiceCode() {
        return SERVICE_CODE;
    }
}
